package com.platform.service;

import com.platform.config.MySocketHandler;
import com.platform.util.ImgUtils;
import com.platform.util.ToolVideo;
import com.platform.utils.ResourceUtil;
import lombok.Data;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.BinaryMessage;
import org.springframework.web.socket.TextMessage;

import java.util.concurrent.atomic.AtomicInteger;

@Service
@Data
public class TestService {
    private AtomicInteger x = new AtomicInteger(0);
    private AtomicInteger y = new AtomicInteger(0);
    public void selectVideo(String openId)  {
        val map = ToolVideo.getAllImg(ResourceUtil.getConfigByName("video.path"));
        val s = MySocketHandler.users.get(openId);
        for (val m : map.entrySet()) {
            try{
                if (m.getValue() != null){
                    val a= ImgUtils.convertImageData(ImgUtils.cutImg(m.getValue(),x.get(),y.get()));
                    if (a != null) {
                        s.sendMessage(new BinaryMessage(a));
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
